Skip to content


tag  jupyter  tips  ai  deep learning  beginner  regression  reinforcement learning  q learning  gym  gymnasium  ardupilot  None  ros2  dds  micro ros  xrce  sitl  plugin  gazebo  garden  SITL  debug  rangefinder  pymavlink  mavros  distance sensor  system_time  timesync  cmake  gtest  ctest  101  cpp  c++  format  fmt  multithreading  spdlog  cyclonedds  eprosima  fastdds  aptly  apt  repository  repo  local  mirror  encryption  pgp  docker  arm  container  state  networking  network  nvidia  python  app  devcontainer  gui  tutorial  volume  mount  compose  multi-stage  stage  docker compose  git  bundle  submodules  github  hooks  pre-commit  lxd  lxc  x11  profile  vscode  marpit  presentation  marp  markdown  mermaid  mkdocs  video  ffmpeg  gstreamer  cheat-sheet  sdp  v4l2loopback  gi  kml  geo  gis  spatial  gdal  ogr  raster  vector  snippets  cheat Sheet  asyncio  future  click  cli  cupy  numpy  gpu  dev container  deb  debian  package  setup  stdeb  project  hydra  yaml  configuration  matplotlib  3d  subplot  open3d  point cloud  template  black  isort  templates  cookiecutter  docs  project document  docstrings  flake8  linter  git-hook  mypy  unittest  pytest  pylint  from a-z  fixture  scope  logging  pytest.ini  mock  parameterize  enum  flag  iterator  generator  yml  logging config  tuple  namedtuple  typing  annotation  generic  literal  protocol  self  typed dict  typevar  pyzmq  zmq  opencv  msgpack  slam  cartographer  action  namespace  remap  control2  demo  diff-drive  ignition  ros2_control  effort  velocity  gdb  qos  plugins  msg  node  zero-copy  shm  algorithm  calibration  diff  pid  dev  colcon  colcon_cd  settings  behavior  py_trees  bt  behavior_trees  blackboard  plot  visualization  debugging  diagnostic  DiagnosticTask  diagnostics  tutorials  gst  math  apm  rat_runtime_monitor  bag  rosbag  rosbags  tools  ros  web  rosbridge  vue  binding  discovery  gazebo-classic  launch  spawn  model  cook  camera  sensors  gps  imu  ray  gazebo_ros_ray_sensor  lidar  ultrsonic  range  ultrasonic  gazebo classic  wrench  urdf  odom  gz  sdf  world  vscode tips  gazebogz-sim-joint-position-controller-system  bridge  simulation  ros_gz_bridge  ign  xacro  diff_drive  odometry  joint_state  argument  OpaqueFunction  DeclareLaunchArgument  LaunchConfiguration  tmux  nav  test  rclpy  goal abort  cancel goal  action client  action server  custom messages  executor  MultiThreadedExecutor  SingleThreadedExecutor  param  dynamic-reconfigure  service  client  setup.py  package.xml  parameter  parameters  custom  msgs  executers  pub  sub  rqt  rviz  rviz2  pose  marker  tf2  local_setup  rosdep  package manager  project settings  vcstool  robot_state_publisher  urdf_to_graphiz  joint  link  zenoh  tags  hands on  webinar  cross-compiler  esp32  nano  jetson  arduino  i2c  sensor  mb1202  uart  serial  tfmini  rpi  teensy  microros  config  material  workshope  texture  joints  tmuxp  loop device  rootfs  embedded  zah  linux  rm  ubuntu  sudo  sudoers  nopasswd  visudo  udev  key  gpg  sign  commands  update-alternative  dpkg  ip  ss  netstat  snap  deploy  ssh  systemd  socat  udp  tc  mtu  select  robotics  path planning  trajectory  speed  pcl  kalman_filter  kalman  filter  control  code  extensions  remote  json  schema  yocto  poky  qemu  projects  courses to follow  matrix  graphics  rotation  2d  course  vision  drone  quad  uav  design  vrx  buoyancy 

Run ROS2 Node#

Run minimal ROS2 node from:

  • cli
  • add namespace
  • remap topic
  • remap node name
  • launch file
  • cli control debug level

Run from cli#

ros2 run params_demos minimal
#
[INFO] [1680205241.556490384] [simple_param_node]: my_int: 3
[INFO] [1680205242.543293520] [simple_param_node]: my_int: 2
[INFO] [1680205243.543186445] [simple_param_node]: my_int: 1
[INFO] [1680205244.543174591] [simple_param_node]: close timer
ros2 node list
# 
/simple_param_node

Add namespace#

terminal 1
ros2 run params_demos minimal --ros-args --remap __ns:=/custom
terminal 2
ros2 node list           
#
/custom/simple_param_node

Remap topic name#

terminal 1
# without namespace
ros2 run params_demos minimal --ros-args --remap /simple_param_node/my_topic:=/new_topic

# with namespace
ros2 run params_demos minimal --ros-args --remap /custom/simple_param_node/my_topic:=/new_topic --remap __ns:=/custom
terminal 2
ros2 node list           
#
/custom/simple_param_node

ros2 topic list 
#
/new_topic

Topic absolute name

topic name start with forward slash are absolute
when you rename topic and the remap topic name are not absolute. namespace add to the topic name as prefix

ros2 run params_demos minimal --ros-args --remap /custom/simple_param_node/my_topic:=new_topic --remap __ns:=/custom

ros2 topic list 
#
/custom_ns/new_topic
ros2 run params_demos minimal --ros-args --remap /custom/simple_param_node/my_topic:=/new_topic --remap __ns:=/custom

ros2 topic list 
#
/new_topic

Add fqn to topic name

Topic and Service name mapping to DDS

fqn = self.get_fully_qualified_name()
self.get_logger().info(f"node name: {node_name}")
self.pub = self.create_publisher(Int32, fqn + TOPIC, 10)

Remap node name#

Terminal 1
ros2 run params_demos minimal --ros-args --remap __node:=node_new_name
Terminal 2
ros2 node list
#
/node_new_name

ros2 topic list
#
/node_new_name/my_topic
/parameter_events
/rosout

Remap node name with namespace#

Terminal 1
run params_demos minimal --ros-args --remap __node:=node_new_name --remap __ns:=/custom
Terminal 2
ros2 node list 
#
/custom/node_new_name

ros2 topic list
#
/custom/node_new_name/my_topic
/parameter_events
/rosout

Note

name = self.get_name()
ns = self.get_namespace()
fqn = self.get_fully_qualified_name()
self.get_logger().info(f"node name: {name}")
self.get_logger().info(f"ns: {ns}")
self.get_logger().info(f"fqn: {fqn}")
ros2 run params_demos minimal --ros-args --remap __node:=node_new_name --remap __ns:=/custom
[INFO] [1680233355.573926310] [custom.node_new_name]: node name: node_new_name
[INFO] [1680233355.574155685] [custom.node_new_name]: ns: /custom
[INFO] [1680233355.574342657] [custom.node_new_name]: fqn: /custom/node_new_name

launch#

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    ld = LaunchDescription()

    sim_node =  Node(
            package='params_demos',
            namespace='custom',
            executable='minimal',
            name='simple_node'
        )


    ld.add_action(sim_node)
    return ld
ros2 node list
/custom/simple_node
#
ros2 topic list
/custom/simple_node/my_topic

remap topics#

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    ld = LaunchDescription()

    sim_node =  Node(
            package='params_demos',
            namespace='custom',
            executable='minimal',
            name='simple_node',
            remappings=[
                ("/custom/simple_node/my_topic", "/new_topic_name")
            ]
        )


    ld.add_action(sim_node)
    return ld
ros2 node list
/custom/simple_node
#
ros2 topic list
/new_topic_name

cli and launch logging level control#

more ros2 logging info

cli#

loging level:

  • debug
  • info
  • warn
  • error
terminal
ros2 run params_demos minimal --ros-args --log-level debug

launch#

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    ld = LaunchDescription()

    sim_node =  Node(
            package='params_demos',
            namespace='custom',
            executable='minimal',
            name='simple_node',
            remappings=[
                ("/custom/simple_node/my_topic", "/new_topic_name")
            ],
            arguments=['--ros-args', '--log-level', 'warn']
        )


    ld.add_action(sim_node)
    return ld

Reference#